using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;

namespace MobileClient
{
	/// <summary>
	/// Summary description for frmOptions.
	/// </summary>
	public class frmOptions : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TabControl tabControl;
		private System.Windows.Forms.MainMenu mnuMain;
		private Microsoft.WindowsCE.Forms.InputPanel pnlSIP;
		private System.Windows.Forms.TabPage tabUserInfo;
		private System.Windows.Forms.TabPage tabServer;
		private System.Windows.Forms.TabPage tabProxy;
		private System.Windows.Forms.TabPage tabFiles;
		private System.Windows.Forms.Label lbluserID;
		private System.Windows.Forms.TextBox txtUserID;
		private System.Windows.Forms.Label lblPassword;
		private System.Windows.Forms.TextBox txtPassword;
		private System.Windows.Forms.Label lblProtocol;
		private System.Windows.Forms.ComboBox cbProtocol;
		private System.Windows.Forms.Label lblServer;
		private System.Windows.Forms.TextBox txtServer;
		private System.Windows.Forms.Label lblPort;
		private System.Windows.Forms.CheckBox chkUseProxy;
		private System.Windows.Forms.Label lblProxy;
		private System.Windows.Forms.TextBox txtProxy;
		private System.Windows.Forms.TabPage tabProxyUser;
		private System.Windows.Forms.Label lblProxyPassword;
		private System.Windows.Forms.Label lblUser;
		private System.Windows.Forms.TextBox txtProxyPort;
		private System.Windows.Forms.Label lblProxyPort;
		private System.Windows.Forms.Label lblStorageLoc;
		private System.Windows.Forms.ComboBox cbStorageLocation;
		private System.Windows.Forms.TextBox txtProxyPassword;
		private System.Windows.Forms.TextBox txtProxyUser;
		private System.Windows.Forms.TextBox txtCompany;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtPort;
	
		public frmOptions()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.tabControl = new System.Windows.Forms.TabControl();
            this.tabUserInfo = new System.Windows.Forms.TabPage();
            this.txtCompany = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.txtPassword = new System.Windows.Forms.TextBox();
            this.lblPassword = new System.Windows.Forms.Label();
            this.txtUserID = new System.Windows.Forms.TextBox();
            this.lbluserID = new System.Windows.Forms.Label();
            this.tabServer = new System.Windows.Forms.TabPage();
            this.txtPort = new System.Windows.Forms.TextBox();
            this.lblPort = new System.Windows.Forms.Label();
            this.txtServer = new System.Windows.Forms.TextBox();
            this.lblServer = new System.Windows.Forms.Label();
            this.cbProtocol = new System.Windows.Forms.ComboBox();
            this.lblProtocol = new System.Windows.Forms.Label();
            this.tabProxy = new System.Windows.Forms.TabPage();
            this.txtProxyPort = new System.Windows.Forms.TextBox();
            this.lblProxyPort = new System.Windows.Forms.Label();
            this.txtProxy = new System.Windows.Forms.TextBox();
            this.lblProxy = new System.Windows.Forms.Label();
            this.chkUseProxy = new System.Windows.Forms.CheckBox();
            this.tabProxyUser = new System.Windows.Forms.TabPage();
            this.txtProxyPassword = new System.Windows.Forms.TextBox();
            this.lblProxyPassword = new System.Windows.Forms.Label();
            this.txtProxyUser = new System.Windows.Forms.TextBox();
            this.lblUser = new System.Windows.Forms.Label();
            this.tabFiles = new System.Windows.Forms.TabPage();
            this.cbStorageLocation = new System.Windows.Forms.ComboBox();
            this.lblStorageLoc = new System.Windows.Forms.Label();
            this.mnuMain = new System.Windows.Forms.MainMenu();
            this.pnlSIP = new Microsoft.WindowsCE.Forms.InputPanel();
            this.tabControl.SuspendLayout();
            this.tabUserInfo.SuspendLayout();
            this.tabServer.SuspendLayout();
            this.tabProxy.SuspendLayout();
            this.tabProxyUser.SuspendLayout();
            this.tabFiles.SuspendLayout();
            this.SuspendLayout();
            // 
            // tabControl
            // 
            this.tabControl.Controls.Add(this.tabUserInfo);
            this.tabControl.Controls.Add(this.tabServer);
            this.tabControl.Controls.Add(this.tabProxy);
            this.tabControl.Controls.Add(this.tabProxyUser);
            this.tabControl.Controls.Add(this.tabFiles);
            this.tabControl.Location = new System.Drawing.Point(0, 0);
            this.tabControl.Name = "tabControl";
            this.tabControl.SelectedIndex = 0;
            this.tabControl.Size = new System.Drawing.Size(238, 264);
            this.tabControl.TabIndex = 0;
            // 
            // tabUserInfo
            // 
            this.tabUserInfo.Controls.Add(this.txtCompany);
            this.tabUserInfo.Controls.Add(this.label1);
            this.tabUserInfo.Controls.Add(this.txtPassword);
            this.tabUserInfo.Controls.Add(this.lblPassword);
            this.tabUserInfo.Controls.Add(this.txtUserID);
            this.tabUserInfo.Controls.Add(this.lbluserID);
            this.tabUserInfo.Location = new System.Drawing.Point(0, 0);
            this.tabUserInfo.Name = "tabUserInfo";
            this.tabUserInfo.Size = new System.Drawing.Size(238, 241);
            this.tabUserInfo.Text = "User";
            // 
            // txtCompany
            // 
            this.txtCompany.Location = new System.Drawing.Point(8, 40);
            this.txtCompany.Name = "txtCompany";
            this.txtCompany.Size = new System.Drawing.Size(216, 21);
            this.txtCompany.TabIndex = 0;
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(8, 8);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(60, 20);
            this.label1.Text = "Company:";
            // 
            // txtPassword
            // 
            this.txtPassword.Location = new System.Drawing.Point(6, 168);
            this.txtPassword.Name = "txtPassword";
            this.txtPassword.PasswordChar = '*';
            this.txtPassword.Size = new System.Drawing.Size(216, 21);
            this.txtPassword.TabIndex = 2;
            // 
            // lblPassword
            // 
            this.lblPassword.Location = new System.Drawing.Point(6, 136);
            this.lblPassword.Name = "lblPassword";
            this.lblPassword.Size = new System.Drawing.Size(60, 20);
            this.lblPassword.Text = "Password:";
            // 
            // txtUserID
            // 
            this.txtUserID.Location = new System.Drawing.Point(6, 104);
            this.txtUserID.Name = "txtUserID";
            this.txtUserID.Size = new System.Drawing.Size(216, 21);
            this.txtUserID.TabIndex = 4;
            // 
            // lbluserID
            // 
            this.lbluserID.Location = new System.Drawing.Point(6, 72);
            this.lbluserID.Name = "lbluserID";
            this.lbluserID.Size = new System.Drawing.Size(36, 20);
            this.lbluserID.Text = "User:";
            // 
            // tabServer
            // 
            this.tabServer.Controls.Add(this.txtPort);
            this.tabServer.Controls.Add(this.lblPort);
            this.tabServer.Controls.Add(this.txtServer);
            this.tabServer.Controls.Add(this.lblServer);
            this.tabServer.Controls.Add(this.cbProtocol);
            this.tabServer.Controls.Add(this.lblProtocol);
            this.tabServer.Location = new System.Drawing.Point(0, 0);
            this.tabServer.Name = "tabServer";
            this.tabServer.Size = new System.Drawing.Size(238, 241);
            this.tabServer.Text = "Server";
            // 
            // txtPort
            // 
            this.txtPort.Location = new System.Drawing.Point(6, 142);
            this.txtPort.Name = "txtPort";
            this.txtPort.Size = new System.Drawing.Size(216, 21);
            this.txtPort.TabIndex = 0;
            // 
            // lblPort
            // 
            this.lblPort.Location = new System.Drawing.Point(6, 110);
            this.lblPort.Name = "lblPort";
            this.lblPort.Size = new System.Drawing.Size(36, 20);
            this.lblPort.Text = "Port:";
            // 
            // txtServer
            // 
            this.txtServer.Location = new System.Drawing.Point(6, 76);
            this.txtServer.Name = "txtServer";
            this.txtServer.Size = new System.Drawing.Size(216, 21);
            this.txtServer.TabIndex = 2;
            // 
            // lblServer
            // 
            this.lblServer.Location = new System.Drawing.Point(6, 44);
            this.lblServer.Name = "lblServer";
            this.lblServer.Size = new System.Drawing.Size(48, 20);
            this.lblServer.Text = "Server:";
            // 
            // cbProtocol
            // 
            this.cbProtocol.Items.Add("http");
            this.cbProtocol.Items.Add("https");
            this.cbProtocol.Location = new System.Drawing.Point(70, 11);
            this.cbProtocol.Name = "cbProtocol";
            this.cbProtocol.Size = new System.Drawing.Size(156, 22);
            this.cbProtocol.TabIndex = 4;
            // 
            // lblProtocol
            // 
            this.lblProtocol.Location = new System.Drawing.Point(6, 12);
            this.lblProtocol.Name = "lblProtocol";
            this.lblProtocol.Size = new System.Drawing.Size(56, 20);
            this.lblProtocol.Text = "Protocol:";
            // 
            // tabProxy
            // 
            this.tabProxy.Controls.Add(this.txtProxyPort);
            this.tabProxy.Controls.Add(this.lblProxyPort);
            this.tabProxy.Controls.Add(this.txtProxy);
            this.tabProxy.Controls.Add(this.lblProxy);
            this.tabProxy.Controls.Add(this.chkUseProxy);
            this.tabProxy.Location = new System.Drawing.Point(0, 0);
            this.tabProxy.Name = "tabProxy";
            this.tabProxy.Size = new System.Drawing.Size(238, 241);
            this.tabProxy.Text = "Proxy";
            // 
            // txtProxyPort
            // 
            this.txtProxyPort.Location = new System.Drawing.Point(6, 142);
            this.txtProxyPort.Name = "txtProxyPort";
            this.txtProxyPort.Size = new System.Drawing.Size(216, 21);
            this.txtProxyPort.TabIndex = 0;
            // 
            // lblProxyPort
            // 
            this.lblProxyPort.Location = new System.Drawing.Point(6, 110);
            this.lblProxyPort.Name = "lblProxyPort";
            this.lblProxyPort.Size = new System.Drawing.Size(36, 20);
            this.lblProxyPort.Text = "Port:";
            // 
            // txtProxy
            // 
            this.txtProxy.Location = new System.Drawing.Point(6, 76);
            this.txtProxy.Name = "txtProxy";
            this.txtProxy.Size = new System.Drawing.Size(216, 21);
            this.txtProxy.TabIndex = 2;
            // 
            // lblProxy
            // 
            this.lblProxy.Location = new System.Drawing.Point(6, 44);
            this.lblProxy.Name = "lblProxy";
            this.lblProxy.Size = new System.Drawing.Size(80, 20);
            this.lblProxy.Text = "Proxy Server:";
            // 
            // chkUseProxy
            // 
            this.chkUseProxy.Location = new System.Drawing.Point(6, 12);
            this.chkUseProxy.Name = "chkUseProxy";
            this.chkUseProxy.Size = new System.Drawing.Size(120, 20);
            this.chkUseProxy.TabIndex = 4;
            this.chkUseProxy.Text = "Use Proxy Server";
            // 
            // tabProxyUser
            // 
            this.tabProxyUser.Controls.Add(this.txtProxyPassword);
            this.tabProxyUser.Controls.Add(this.lblProxyPassword);
            this.tabProxyUser.Controls.Add(this.txtProxyUser);
            this.tabProxyUser.Controls.Add(this.lblUser);
            this.tabProxyUser.Location = new System.Drawing.Point(0, 0);
            this.tabProxyUser.Name = "tabProxyUser";
            this.tabProxyUser.Size = new System.Drawing.Size(238, 241);
            this.tabProxyUser.Text = "P User";
            // 
            // txtProxyPassword
            // 
            this.txtProxyPassword.Location = new System.Drawing.Point(6, 110);
            this.txtProxyPassword.Name = "txtProxyPassword";
            this.txtProxyPassword.PasswordChar = '*';
            this.txtProxyPassword.Size = new System.Drawing.Size(216, 21);
            this.txtProxyPassword.TabIndex = 0;
            // 
            // lblProxyPassword
            // 
            this.lblProxyPassword.Location = new System.Drawing.Point(6, 76);
            this.lblProxyPassword.Name = "lblProxyPassword";
            this.lblProxyPassword.Size = new System.Drawing.Size(98, 20);
            this.lblProxyPassword.Text = "Proxy Password:";
            // 
            // txtProxyUser
            // 
            this.txtProxyUser.Location = new System.Drawing.Point(6, 42);
            this.txtProxyUser.Name = "txtProxyUser";
            this.txtProxyUser.Size = new System.Drawing.Size(216, 21);
            this.txtProxyUser.TabIndex = 2;
            // 
            // lblUser
            // 
            this.lblUser.Location = new System.Drawing.Point(6, 12);
            this.lblUser.Name = "lblUser";
            this.lblUser.Size = new System.Drawing.Size(86, 20);
            this.lblUser.Text = "Proxy User ID:";
            // 
            // tabFiles
            // 
            this.tabFiles.Controls.Add(this.cbStorageLocation);
            this.tabFiles.Controls.Add(this.lblStorageLoc);
            this.tabFiles.Location = new System.Drawing.Point(0, 0);
            this.tabFiles.Name = "tabFiles";
            this.tabFiles.Size = new System.Drawing.Size(238, 241);
            this.tabFiles.Text = "Files";
            // 
            // cbStorageLocation
            // 
            this.cbStorageLocation.Location = new System.Drawing.Point(6, 44);
            this.cbStorageLocation.Name = "cbStorageLocation";
            this.cbStorageLocation.Size = new System.Drawing.Size(216, 22);
            this.cbStorageLocation.TabIndex = 0;
            // 
            // lblStorageLoc
            // 
            this.lblStorageLoc.Location = new System.Drawing.Point(6, 12);
            this.lblStorageLoc.Name = "lblStorageLoc";
            this.lblStorageLoc.Size = new System.Drawing.Size(88, 20);
            this.lblStorageLoc.Text = "Store Files To:";
            // 
            // frmOptions
            // 
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
            this.ClientSize = new System.Drawing.Size(238, 295);
            this.Controls.Add(this.tabControl);
            this.Menu = this.mnuMain;
            this.Name = "frmOptions";
            this.Text = "Options";
            this.Load += new System.EventHandler(this.frmOptions_Load);
            this.Closing += new System.ComponentModel.CancelEventHandler(this.frmOptions_Closing);
            this.tabControl.ResumeLayout(false);
            this.tabUserInfo.ResumeLayout(false);
            this.tabServer.ResumeLayout(false);
            this.tabProxy.ResumeLayout(false);
            this.tabProxyUser.ResumeLayout(false);
            this.tabFiles.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		#endregion

		private void frmOptions_Load(object sender, System.EventArgs e)
		{
			FindStorageLocations();
			LoadSettings();
		}

		private void FindStorageLocations()
		{
			FileInfo objInfo;

			// always add the the actual Device's memory to the location
			cbStorageLocation.Items.Add("Device Memory");
			// get all of the high level directories
			string[] strDirectories = Directory.GetDirectories("\\", "*");
			// walk each directory and check to see
			// if it is Temporary and a Directory indicating
			// a removable storage device.
			foreach(string strDir in strDirectories)
			{
				// create a new FileInfo Object
				objInfo = new FileInfo(strDir);
				// check to see if the directory meets our
				// criteria
				if((int)objInfo.Attributes == (int)FileAttributes.Directory + (int)FileAttributes.Temporary)
				{
					// add the directory to the device
					cbStorageLocation.Items.Add(strDir);
				}
			}
		}

		private void LoadSettings()
		{
			string strPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase + ".config";

			Settings objSettings = new Settings();
			objSettings.FilePath = strPath;
			objSettings.Read();

			txtCompany.Text = objSettings.Company;
			txtUserID.Text = objSettings.UserID;
			txtPassword.Text = objSettings.Password;
			cbProtocol.Text = objSettings.Protocol;
			txtServer.Text = objSettings.Server;
			txtPort.Text = objSettings.Port;
			chkUseProxy.Checked = objSettings.UseProxy;;
			txtProxy.Text = objSettings.ProxyServer;
			txtProxyPort.Text = objSettings.ProxyPort;
			txtProxyUser.Text = objSettings.ProxyUserID;
			txtProxyPassword.Text = objSettings.ProxyPassword;
			cbStorageLocation.Text = objSettings.StorageLocation;
		}

		private void SaveSettings()
		{
			string strPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase + ".config";

			Settings objSettings = new Settings();
			objSettings.FilePath = strPath;

			objSettings.Company = txtCompany.Text;
			objSettings.UserID = txtUserID.Text;
			objSettings.Password = txtPassword.Text;
			objSettings.Protocol = cbProtocol.Text;
			objSettings.Server = txtServer.Text;
			objSettings.Port = txtPort.Text;
			objSettings.UseProxy = chkUseProxy.Checked;
			objSettings.ProxyServer = txtProxy.Text;
			objSettings.ProxyPort = txtProxyPort.Text;
			objSettings.ProxyUserID = txtProxyUser.Text;
			objSettings.ProxyPassword = txtProxyPassword.Text;
			objSettings.StorageLocation = cbStorageLocation.Text;

			objSettings.Write();
		}

		private void frmOptions_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			SaveSettings();
		}

	}
}
